package com.ruoyi.thgd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.thgd.domain.ThgdZdFile;
import com.ruoyi.thgd.service.IThgdZdFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.thgd.domain.ThgdZd;
import com.ruoyi.thgd.service.IThgdZdService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * zdInfoController
 *
 * @author chenhs
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/thgd/zdInfo")
public class ThgdZdController extends BaseController
{
    @Autowired
    private IThgdZdService thgdZdService;
    @Autowired
    private IThgdZdFileService thgdZdFileService;

    /**
     * 查询zdInfo列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ThgdZd thgdZd)
    {
        startPage();
        List<ThgdZd> list = thgdZdService.selectThgdZdList(thgdZd);
        return getDataTable(list);
    }

    /**
     * 查询zdInfo列表
     * 不分页
     */
    @GetMapping("/noList")
    public TableDataInfo noList(ThgdZd thgdZd)
    {
        List<ThgdZd> list = thgdZdService.selectThgdZdList(thgdZd);
        return getDataTable(list);
    }

    /**
     * 导出zdInfo列表
     */
    @Log(title = "zdInfo", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThgdZd thgdZd)
    {
        List<ThgdZd> list = thgdZdService.selectThgdZdList(thgdZd);
        ExcelUtil<ThgdZd> util = new ExcelUtil<ThgdZd>(ThgdZd.class);
        util.exportExcel(response, list, "zdInfo数据");
    }

    /**
     * 获取zdInfo详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        ThgdZd zdInfo = thgdZdService.selectThgdZdById(id);
        if(zdInfo == null){
            return warn("站点信息不存在");
        }
        //根据站点信息获取图片
        ThgdZdFile zdFileQuery = new ThgdZdFile();
        zdFileQuery.setZdId(zdInfo.getId());
        List<ThgdZdFile> zdFileList = thgdZdFileService.selectThgdZdFileList(zdFileQuery);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("zdInfo",zdInfo);
        jsonObject.put("zdFileList",zdFileList);
        return success(jsonObject);
    }

    /**
     * 新增zdInfo
     */
    @Log(title = "zdInfo", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ThgdZd thgdZd)
    {
        return toAjax(thgdZdService.insertThgdZd(thgdZd));
    }

    /**
     * 修改zdInfo
     */
    @Log(title = "zdInfo", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ThgdZd thgdZd)
    {
        return toAjax(thgdZdService.updateThgdZd(thgdZd));
    }

    /**
     * 删除zdInfo
     */
    @Log(title = "zdInfo", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(thgdZdService.deleteThgdZdByIds(ids));
    }
}
